package net.daum.webtoon.android.util;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

/**
 * Simple AlertDilaog �� Class
 * 
 * @author geekprogramer@gmail.com
 * 
 */
public class AlertDialogUtil {

	/**
	 * Alert(���ư Alert Dialog)�� ��
	 * 
	 * @param context
	 * @param message
	 * @return
	 */
	public static Dialog createAlert(Context context, String message) {
		return createAlert(context, null, message, null, null);
	}

	/**
	 * Alert(���ư Alert Dialog)�� ��
	 * 
	 * @param context
	 * @param message
	 * @param btnText
	 * @return
	 */
	public static Dialog createAlert(Context context, String message,
			String btnText) {
		return createAlert(context, null, message, btnText, null);
	}

	/**
	 * Alert(���ư Alert Dialog)�� ��
	 * 
	 * @param context
	 * @param title
	 * @param message
	 * @param btnText
	 * @param listener
	 * @return
	 */
	public static Dialog createAlert(Context context, String title,
			String message, String btnText, OnClickListener listener) {
		AlertDialog dialog = new AlertDialog.Builder(context).create();
		dialog.setTitle(title != null ? title : null);
		dialog.setMessage(message);
		dialog.setButton(btnText != null ? btnText : "OK", listener);
		return dialog;
	}

	/**
	 * Confirm(����ư Alert Dialog)�� ��
	 * 
	 * @param context
	 * @param message
	 * @param leftListener
	 * @return
	 */
	public static Dialog createConfirm(Context context, String message,
			OnClickListener leftListener) {
		return createConfirm(context, null, message, null, leftListener, null,
				null);
	}

	/**
	 * Confirm(����ư Alert Dialog)�� ��
	 * 
	 * @param context
	 * @param title
	 * @param message
	 * @param btnLeftText
	 * @param leftListener
	 * @param btnRightText
	 * @param rightListener
	 * @return
	 */
	public static Dialog createConfirm(Context context, String title,
			String message, String btnLeftText, OnClickListener leftListener,
			String btnRightText, OnClickListener rightListener) {
		AlertDialog dialog = new AlertDialog.Builder(context).create();
		dialog.setTitle(title != null ? title : null);
		dialog.setMessage(message);
		dialog.setButton(btnLeftText != null ? btnLeftText : "YES",
				leftListener);
		dialog.setButton2(btnRightText != null ? btnRightText : "NO",
				rightListener);
		return dialog;
	}

	public static class ListDialogInfo {
		public ArrayList<String> items;
		public DialogInterface.OnClickListener click;

		public ListDialogInfo() {
		}

		public ListDialogInfo(ArrayList<String> items,
				DialogInterface.OnClickListener click) {
			this.items = items;
			this.click = click;
		}

	}

	public static Dialog createListDialog(Context context, String title,
			ListDialogInfo dialogInfo, String btnLeftText,
			OnClickListener leftListener, String btnRightText,
			OnClickListener rightListener) {
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setTitle(title != null ? title : null);
		CharSequence[] items = new CharSequence[dialogInfo.items.size()];
		int idx = 0;
		for (Object itemObj : dialogInfo.items.toArray()) {
			items[idx] = itemObj.toString();
			idx++;
		}
		builder.setSingleChoiceItems(items, 0, dialogInfo.click);
		builder.setPositiveButton(btnLeftText, leftListener);
		builder.setNegativeButton(btnRightText, rightListener);
		return builder.create();
	}
}
